package GUI;

import java.util.Vector;
import Objetos.Pedido;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ActiveRichTextField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class ListFieldManager {
	
	private Vector itemVector;
	//private RichTextField first;
	
	public ListFieldManager(Vector items)
	{
		if(!items.isEmpty()){
			itemVector = items;
		}
	}
	 
	public Manager paintListField (){
		VerticalFieldManager listF = new VerticalFieldManager();
		
		for (int i=0; i<itemVector.size(); i++)
		{
			Pedido item = (Pedido) itemVector.elementAt(i);
			LayoutManager lm = new LayoutManager(Color.WHITE,0x004E6DA9);
			
			Font fontDateBold = Font.getDefault().derive(Font.BOLD,30);
			ActiveRichTextField date = new ActiveRichTextField(item.getNombre(), LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | DrawStyle.TOP | RichTextField.NON_FOCUSABLE);
			date.setFont(fontDateBold);
			
			
			Font fontNews = Font.getDefault().derive(Font.PLAIN,20);
			
			HorizontalFieldManager hm = new HorizontalFieldManager();
			RichTextField text = new RichTextField(item.getCodigo());
			RichTextField text1 = new RichTextField(""+item.getPrecio());
			text.setFont(fontNews);
			
			if(i==0){
				//first = text;
			}
			
			VerticalFieldManager vfm = new VerticalFieldManager();
			
			vfm.add(date);
			hm.add(text);
			hm.add(text1);
			vfm.add(hm);
			
			//vfm.add(text1);
			
			lm.add(vfm);
			
			listF.add(lm);
			listF.add(new SeparatorField());
		}
		if (itemVector.size()>0)
			return listF;
		else
		{
			ActiveRichTextField vacio = new ActiveRichTextField("No Existen Items por el Momento...!", RichTextField.TEXT_ALIGN_HCENTER);
			listF.add(vacio);
			return listF;
		}
	}

	public void focusFirstElement() {
		// TODO Auto-generated method stub
		//first.setFocus();
	}

}
